package controllers;

import play.*;
import play.mvc.*;

import java.util.*;

import models.*;

public class Articles extends Controller {
	
	public static void index(QueryBean queryBean){
		
		
		String hql = "from Article article where 1=1";
		
		if(queryBean == null){
			queryBean = new QueryBean();
		}
		
		//页数计算
		queryBean.quantityEachPage=50;
		queryBean.totalQuantity = Article.count(hql.toString(), null);
		queryBean.totalPage = (queryBean.totalQuantity/queryBean.quantityEachPage + 1);
		if(queryBean.totalPage < queryBean.currentPage) {
			queryBean.currentPage = queryBean.totalPage;
		}
		
		//查询结果
		List<Article> articleList = Article.find(hql.toString()).fetch(
				(int)queryBean.currentPage, queryBean.quantityEachPage);
		
		render(articleList,queryBean);
	}
	
	public static void show(Long id){
		Article article = Article.findById(id);
		System.out.println(article.content);
		render(article);
	}
}